import java.util.Scanner;

public class _01背包朴素写法 {
    static int N = 1010;
    static int[][] f = new int[N][N];
    static int[] v = new int[N];
    static int[] w = new int[N];
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int m = s.nextInt();
        for(int i=1;i<=n;i++) {
            v[i] = s.nextInt();
            w[i] = s.nextInt();
        }
        System.out.print("   ");
        for (int i = 0; i <=m; i++) System.out.print(i+"  ");
        System.out.println();
        System.out.print("0: ");
        for (int i = 0; i <=m; i++)  System.out.print(0+"  ");
        System.out.println();

        for (int i = 1; i <=n ; i++) {
            System.out.print(i+": ");
            for (int j = 0; j <= m; j++) {
                f[i][j]=f[i-1][j];
                if(j>=v[i]) f[i][j]=Math.max(f[i-1][j],f[i-1][j-v[i]]+w[i]);
                System.out.print(f[i][j]+"  ");
            }
            System.out.println();
        }
       // System.out.println(f[n][m]);

    }

}
